﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TexasHoldem.RankedHands
{
    public class StraightFlushHand: RankedHand
    {
        private StraightFlushHand(Hand hand) : base(hand) { }
        public static StraightFlushHand TryCreateFrom(Hand hand) 
        {
            return FindStraightFlush(hand.Cards) != null ? new StraightFlushHand(hand) : null;
        }

        public override string RankName
        {
            get
            {
                var topCard = FindStraightFlush(Cards).First().Face;
                return topCard == CardFace.Ace ? "Royal Flush" : "Straight Flush";
            }
        }

        protected override ushort RankingStrength
        {
            get { return 8; }
        }

        protected override IEnumerable<Card> FindDefiningCards()
        {
            return FindStraightFlush(Cards);
        }

        private static IEnumerable<Card> FindStraightFlush(IEnumerable<Card> cards)
        {
            var flush = cards.GroupBy(c => c.Suit).FirstOrDefault(g => g.Count() >= 5);
            if (flush == null) return null;
            return new StraightFindingStrategy().FindStraight(flush);
        }
    }
}
